package www.openteam.com.tool;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;

/**
 * Created by kylin on 2016/10/24.
 */

public class ItemTouchTool extends ItemTouchHelper.Callback {
    private int listFlags ;
    private int swipeFlags ;
    private RecyclerView recyclerView;

    public ItemTouchTool(RecyclerView recyclerView){
        this.recyclerView =recyclerView;
    }


    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        listFlags =0;
        swipeFlags=0;
        if (recyclerView.getLayoutManager() instanceof LinearLayoutManager){
               listFlags  =ItemTouchHelper.UP | ItemTouchHelper.DOWN ;
        }else{
            listFlags =ItemTouchHelper.UP|ItemTouchHelper.DOWN
                    |ItemTouchHelper.LEFT|ItemTouchHelper.RIGHT;
        }
        return makeMovementFlags(listFlags ,swipeFlags);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            int positon =viewHolder.getAdapterPosition();
            recyclerView.getAdapter().notifyItemRemoved(positon);

    }
}
